// 文件路径: src/main/java/com/cupk/controllers/DashboardController.java
// 请用以下内容完全替换您现有的文件

package com.cupk.controllers;

import com.cupk.dtos.DashboardDataDto;
import com.cupk.services.DashboardService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dashboard")
@RequiredArgsConstructor
public class DashboardController {

    private final DashboardService dashboardService;

    /**
     * 获取用户仪表盘的核心静态数据
     * (KPIs, Project Progress, Task Distribution, Recent Activities)
     */
    @GetMapping("/data")
    @PreAuthorize("isAuthenticated()")
    public ResponseEntity<DashboardDataDto> getDashboardData(Authentication authentication) {
        return ResponseEntity.ok(dashboardService.getDashboardData(authentication.getName()));
    }

    /**
     * 动态获取月度趋势图数据
     * @param type - 可选值: PROJECTS, TASKS, PUBLICATIONS, BUDGET
     */
    @GetMapping("/monthly-trend")
    @PreAuthorize("isAuthenticated()")
    public ResponseEntity<List<DashboardDataDto.MonthlyChartPoint>> getMonthlyTrend(
            Authentication authentication,
            @RequestParam(defaultValue = "PROJECTS") String type) {
        return ResponseEntity.ok(dashboardService.getMonthlyTrendData(authentication.getName(), type));
    }
}